//
//  LPLeftViewController.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/15.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPLeftViewController.h"
#import "XLSlideMenu.h"
#import "LPLeftHeaderView.h"
#import "LpLeftTableViewCell.h"
#import "HFStretchableTableHeaderView.h"
#import "ZJBOorganizationModel.h"
#import "ZJReportDetailViewController.h"
#import "BranchOpenPartyOrganizationViewController.h"
/**  我的信息  */
#import "MyInformationViewController.h"

#import "LPCostomPressentAnimationSimilarityPushAnimation.h"
#import "ZJNavigationController.h"
/**  设置  */
#import "MySettingViewController.h"

#import "ZJWebViewController.h"
#import "MyBranchPartyFootPrintViewController.h"
#import "MyInforLookerWeiMaViewController.h"

/** 党员报到 */
#import "ZJReportViewController.h"
#import "LPLeftClaimRequestViewController.h"
#import "LPLeftOrderResouceViewController.h"
#define CELLID @"LpLeftTableViewCell.h"
#define HEADERID @"HEADERVIEW"
@interface LPLeftViewController ()<UITableViewDelegate,UITableViewDataSource,LPLeftHeaderDelegate>
//{
//    MySettingViewController *_mySettingViewController;
//}
/**  table  */
@property (strong, nonatomic) UITableView  *tableView;
/**  标题  */
@property (strong, nonatomic) NSArray  *dataArray;
/**    */
@property (strong, nonatomic) HFStretchableTableHeaderView  *hfStretch;
@end

@implementation LPLeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigView.hidden = YES;
    [self getDataSource];
    [self layoutUI];
}

#pragma mark - 数据
- (void)getDataSource{
    
    NSArray *array = @[@{@"image": @"sidebar_wodeyuyue", @"title": @"我的预约"},
                       @{@"image": @"sidebar_wodexuqiu", @"title": @"我的需求"},
                       @{@"image": @"sidebar_wodejifen", @"title": @"我的积分"},
                       @{@"image": @"sidebar_jifenpaiming", @"title": @"积分排行"},
                       @{@"image": @"sidebar_wodeerweima", @"title": @"我的二维码"},
                       @{@"image": @"sidebar_wodexinxi", @"title": @"我的信息"},
                       @{@"image": @"sidebar_gangweiyiyuan", @"title": @"岗位意愿"},
                       @{@"image": @"sidebar_suoshuzhibu", @"title": @"所属支部"},
                       @{@"image": @"sidebar_shezhi", @"title": @"设置"}
                       ];
    
  
    self.dataArray = @[array];
    
}


#pragma mark - 界面
- (void)layoutUI{
    [self.view addSubview:self.tableView];
    LPLeftHeaderView *header = [[LPLeftHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.xl_sldeMenu.menuWidth, 200 * [UIScreen zj_screenHScale])];
    
//    self.tableView.tableHeaderView = header;
//    header.delegate = self;
    [self.hfStretch stretchHeaderForTableView:self.tableView withView:header imageView:header.backImageView share:header.name headerImaheView:header.headerImageView erweima:header.erweimaLabel];
    
    
    UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.xl_sldeMenu.menuWidth, 10 * [UIScreen zj_screenHScale])];
    footer.backgroundColor = [UIColor themeGrayColor];
    self.tableView.tableFooterView = footer;
    
}


#pragma mark - 私有方法


#pragma mark - LPLeftHeaderDelegate
- (void)LPLeftHeadertap_erweima:(BOOL)tap{
    MyInforLookerWeiMaViewController *vc = [MyInforLookerWeiMaViewController new];

    [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];

}

- (void)LPLeftHeadertap_header:(BOOL)tap{
    MyInformationViewController *vc = [MyInformationViewController new];
    [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.hfStretch scrollViewDidScroll:scrollView];
}

#pragma mark - UITableViewDataSource,UITableViewDelegate
/**  返回组个数  */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}
/**  返回cell个数  */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return ((NSArray *)self.dataArray[section]).count;
}
/**  返回cell高度  */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 45 * [UIScreen zj_screenHScale];
}
/**  cell初始化  */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LpLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELLID];
        cell.data = ((NSArray *)self.dataArray[indexPath.section])[indexPath.row];
    return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HEADERID];
    view.backgroundColor = [UIColor zj_colorWithHexString:@"ebebeb"];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10 * [UIScreen zj_screenHScale];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0000000001;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
/**  cell的点击事件  */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSArray *array = self.dataArray[indexPath.section];
    NSDictionary *dic = array[indexPath.row];
    NSString *title = dic[@"title"];
    if ([title isEqualToString:@"我的积分"]) {
        ZJWebViewController *vc = [ZJWebViewController new];
        vc.titleString = @"我的积分";
        vc.urlString = [NSString stringWithFormat:@"%@/WeChat/views/index_hd.html#/fxd_shibei/%@",HTMLURL,ZJUSERINFORMODEL.ORG_ACCOUNT.ID];
        [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"设置"]){
        MySettingViewController * vc = [[MySettingViewController alloc]init];
        [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"我的需求"]){
        LPLeftClaimRequestViewController *vc = [LPLeftClaimRequestViewController new];
        [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"我的预约"]){
        LPLeftOrderResouceViewController *vc = [LPLeftOrderResouceViewController new];
        [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"我的二维码"]){
        MyInforLookerWeiMaViewController *vc = [MyInforLookerWeiMaViewController new];
        [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"我的信息"]){
        MyInformationViewController *vc = [MyInformationViewController new];
        [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"岗位意愿"]){
        ZJBOorganizationModel *model = [ZJBOorganizationModel new];
        model.ID = ZJUSERINFORMODEL.DEPT_MODEL_JOB.ID;
        ZJReportDetailViewController *vc = [[ZJReportDetailViewController alloc] init];
        vc.model = model;
        vc.titleString = @"岗位意愿";
        [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];
    }else if ([title isEqualToString:@"所属支部"]){
        BranchOpenPartyOrganizationViewController *vc = [BranchOpenPartyOrganizationViewController new];
        BranchPartyOrgizationModel*model = [BranchPartyOrgizationModel new];
        model.ID = ZJUSERINFORMODEL.DEPT_MODEL_BOOK.ID;
        model.DEPT_NAME = ZJUSERINFORMODEL.DEPT_MODEL_BOOK.DEPT_NAME;
        vc.model = model;
        [[ToolClass getMainNavigationController] pushViewController:vc animated:YES];
    }
    
}


#pragma mark - 懒加载
/**  初始化tableView  */
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.xl_sldeMenu.menuWidth, self.view.bounds.size.height) style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = [UIColor themeGrayColor];
        _tableView.tableFooterView = [[TenGrayShadowView  alloc] initWithFrame:CGRectMake(0, 0, self.xl_sldeMenu.menuWidth, 10)];
        [_tableView registerClass:[LpLeftTableViewCell class] forCellReuseIdentifier:CELLID];
        
    }
    return _tableView;
}

- (HFStretchableTableHeaderView *)hfStretch{
    if (!_hfStretch) {
        _hfStretch = [[HFStretchableTableHeaderView alloc] init];;
    }
    return _hfStretch;
}
@end
